package MyFile;

import java.io.File;

public class demo4 {
    public static void main(String[] args) {
        File file = new File("D:\\software\\下载\\aaaaaaa");
        delete(file);
    }

    public static void delete(File file){
        if (file == null || !file.exists()){
            System.out.println("异常");
            return;
        }
        if (file.isFile()){
            file.delete();
            return;
        }
        File[] files = file.listFiles();
        if (files == null){
            return;
        }

        for (int i = 0; i < files.length; i++) {
            File tempFile = files[i];
            if (tempFile.isFile()){
                tempFile.delete();
            }else {
                delete(tempFile);
            }
        }
        file.delete();
    }
}
